 <?php
 	header("Content-type:text/html; charset=utf-8");
 	// 制定允许其他域名访问
	header("Access-Control-Allow-Origin:*");
	// 响应类型
	header('Access-Control-Allow-Methods:POST');
	// 响应头设置
	header('Access-Control-Allow-Headers:x-requested-with, content-type');
    include 'config.php';

    $name=trim($_POST['username']);
	$password=$_POST['password'];
	$sql = "select * from t_admin where user='$name'";
	$info = mysqli_query($conn,$sql);
	@$res = mysqli_num_rows($info);
	$data1=1;$data2=1;$data3=1;$data4=1;
	if(empty($name)){
		$data1 = '用户名或密码不能为空';
	}else if(empty($password)){
		$data1 = '用户名或密码不能为空';
	}else{	
		if($res){
			$data2 = '用户名已存在';
		}else{
			$sql1 ="insert into t_admin(user,pwd) values('".$name."','" .($password)."')";
			$result = mysqli_query($conn,$sql1);
			if($result){
		 			$data3 = '注册成功';
			}else{
		 			$data4 = '注册失败';
			}
		}
	$arr = [$data1,$data2,$data3,$data4];
	echo json_encode($arr);
}	

$conn->close();

?>                                           
